package cn.doctorpda.conference.utils;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

public class TimeCountUtil extends CountDownTimer {
    private TextView tv;// 按钮

    public TimeCountUtil(long millisInFuture,
                         long countDownInterval, TextView tv) {
        super(millisInFuture, countDownInterval);
        this.tv = tv;
    }

    @SuppressLint("NewApi")
    @Override
    public void onTick(long millisUntilFinished) {
        tv.setEnabled(false);// 设置不能点击
        tv.setText(millisUntilFinished / 1000 + "秒后可重新发送");// 设置倒计时时间

        tv.setTextSize(15f);
        Spannable span = new SpannableString(tv.getText().toString());// 获取按钮的文字
        span.setSpan(new ForegroundColorSpan(Color.RED), 0, 2,
                Spannable.SPAN_INCLUSIVE_EXCLUSIVE);// 将倒计时时间显示为红色
        tv.setText(span);

    }

    @SuppressLint("NewApi")
    @Override
    public void onFinish() {
        tv.setText("重新获取验证码");
        tv.setEnabled(true);// 重新获得点击
//		tv.setBackgroundResource(R.drawable.corners_bg_orange);
    }

}
